﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Practices.Unity;
using Apps.Models;
using Apps.Common;
using System.Transactions;
using Apps.Models.Flow;
using Apps.IBLL.Flow;
using Apps.IDAL.Flow;
using Apps.BLL.Core;
using Apps.Models.Enum;
using Apps.Locale;
using System.Linq.Expressions;

namespace Apps.BLL.Flow
{
    public partial class Flow_FormContentStepCheckBLL
    {
     
        public List<Flow_FormContentStepCheckModel> GetListByFormId(string formId, string contentId)
        {
            IQueryable<Flow_FormContentStepCheck> queryData = null;

            queryData = m_Rep.GetListByFormId(formId,contentId);

            return CreateModelList(ref queryData);
        }

        public virtual bool Deletes(ref ValidationErrors errors, Expression<Func<Flow_FormContentStepCheck, bool>> whereLambda)
        {
            try
            {
                using (DBContainer db = new DBContainer())
                {

                    foreach (var entity in db.Flow_FormContentStepCheck.Where(whereLambda))
                    {
                        db.Entry(entity).State = System.Data.Entity.EntityState.Deleted;
                    }

                    if (db.SaveChanges() > 0)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }

                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return false;
            }
        }

        public void ResetCheckStateByFormCententId(string stepCheckId, string contentId, int checkState, int checkFlag)
        {
            m_Rep.ResetCheckStateByFormCententId(stepCheckId, contentId, checkState, checkFlag);
        }
    
    }
}
